// pages/withdrawalDetails/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    type:1,
    page:1,
    pageTotal:0,
    storeList:[],
    keyword:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },
  search(e){
    this.setData({
      keyword:e.detail.value
    })
  },
  searchOk(){
    this.setData({
      storeList:[]
    })
    this.storeDepotPage()
  },
  tipClick(e){
    console.log(e)
    let index = e.currentTarget.dataset.index
    this.setData({
      tabIndex:index
    })
  },
  onCheckbox(event) {
    this.setData({
      checked: event.detail,
    });
  },
  onStepper(event) {
    console.log(event.detail);
  },
  submit(){
    wx.navigateBack({
      delta: 1
    })
  },
  storeDepotPage(){
    let data = {
      id:wx.getStorageSync('userInfo').storeId,
      page:this.data.page,
      limit:10,
      keyword:this.data.keyword
    }
    app.agriknow.storeDepotPage(data).then(res=>{
      console.log(res)
      let storeList = this.data.storeList
      if(res.data.list.length>0){
        res.data.list.forEach((item,index)=>{
          storeList.push(item)
        })
        this.setData({
          storeList:storeList
        })
      }else{
        this.tipsMessage('没有更多了！')
      }
    })
  },
  gotoGyDetail(e){
    console.log(e)
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/gycpList/index?id='+id,
    })
  },
  //触底加载
  scrollbottom() {
    console.log(1)
    this.setData({
      page: this.data.page + 1,
    });
    this.storeDepotPage()
  },
  //提示信息
  tipsMessage(text) {
    wx.showToast({
      title: text,
      icon: 'none',
      duration: 2000,
      mask: true
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.storeDepotPage()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})